<?php
$connect = mysqli_connect('localhost','root','root','thinkcmf');
mysqli_set_charset($connect,'utf8');
if(!$connect){
    echo '数据库连接失败';
    die;
}
    $sql = "select * from cmf_student";
    $query = mysqli_query($connect,$sql);
    $data = mysqli_fetch_all($query,MYSQLI_ASSOC);
    if($data){
        echo jsonReturn(1, '学生列表获取成功', $data);
    }

function jsonReturn($code = 1, $msg = '', $data = [])
{
    $arr =
        [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
    return json_encode($arr);
}